import React from 'react'
import {
    Form,
    Input,
    Button,
    Toast
} from "antd-mobile"
import {setLogin} from "../../api"
import { useNavigate } from 'react-router'

function Index() {
    const navigate=useNavigate()
    const onFinish = (value: any) => {
        // console.log(value)
        setLogin(value).then((res:any)=>{
            console.log(res.data)
            if(res.code===200){
                localStorage.setItem('token',res.data)
                navigate('/main')
                alert(res.mes)
            }else{
                alert(res.mes)
            }
            
            
        })
    }
    return (
        <div>
            <Form
                layout='horizontal'
                onFinish={(value: any) => onFinish(value)}
                footer={
                    <Button block type='submit' color='primary'>
                        提交
                    </Button>
                }
            >
                <Form.Item
                    name='username'
                    label='姓名'
                    rules={[{ required: true, message: '姓名不能为空' }]}
                >
                    <Input placeholder='请输入姓名' />
                </Form.Item>
                <Form.Item
                    name='password'
                    label='密码'
                    rules={[{ required: true, message: '密码不能为空' }]}
                >
                    <Input placeholder='请输入密码' />
                </Form.Item>
            </Form>
        </div>
    )
}

export default Index
